package com.morphiastic;

import java.io.IOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Set;

import org.elasticsearch.common.xcontent.XContentBuilder;

import com.morphiastic.analysis.analyzers.ElasticAnalyzer;





/**
 * Common interface for all types of indexedFields 
 * 
 * @author Alex
 *
 */
public interface IndexedField {
	
	/**
	 * adds the settings (analyzer, tokenizer etc ..) of the fields to the settings definition
	 * in order to be added to the index metadata
	 * @param mappingBuilder
	 * @throws IOException
	 */
	public void addIndexFieldSettings(XContentBuilder mappingBuilder) throws IOException ;
	
	/**
	 * Adds the field's content to the content builder
	 * in order to be indexed
	 * @param mappingBuilder
	 * @param o the object to index
	 * @param maxCircularRefDepth the maximum depth at which we should go ... this can be null if not relevant. 
	 * The amount is initialized the first time an embedded field is encountered 
	 * @param known the fields that already have been indexed and the number of times they have been. 
	 * This is used in conjunction with maxCircularRefDepth to avoid indexing infinite loops
	 * @return the content builder to which the field was added == the one passed in parameter
	 * 
	 */
	public XContentBuilder writeIndexedField(XContentBuilder mappingBuilder ,  Object o, ElasticStore es, Integer maxCircularRefDepth, IdentityHashMap<AccessibleObject, Integer> known )throws IOException ;

//	/**
//	 * converts the passed Object to a standalone JSON object
//	 * @param o
//	 * @param es
//	 * @return
//	 */
//	public XContentBuilder toJSON(Object o, ElasticStore es);
//	
	/**
	 * get all the analyzers that were defined inside this fields annotations
	 * @return
	 */
	public Set<ElasticAnalyzer> getAnalyzers();
	

	/**
	 * Add the map of this indexed field's settings to the provided map 
	 * @param props
	 */
	public void addFieldSettingsMap(HashMap<String, Object> props);
	
}
